<template>
    <sky-base-popup title="确认发货" ref="skyBasePopupRef">
        <view class="form-box">
            <uni-forms ref="formRef" :modelValue="formData" :rules="rules">
                <uni-forms-item label="驳回原因" name="reason">
                    <uni-easyinput type="text" v-model="formData.reason" placeholder="请输入驳回原因"/>
                </uni-forms-item>
            </uni-forms>
        </view>
        <template #footer>
            <up-button type="primary" shape="circle" color="#b07f63" text="确认发货" @tap="qly.form.pass(confirm,formRef)"></up-button>
        </template>
    </sky-base-popup>
</template>
<script setup>

const emits=defineEmits(['success'])
const skyBasePopupRef = ref()
const formRef = ref()
const formData = ref({
    order_id: '',
    reason: '',
    status:2
})
const rules = {
    reason: {
        rules: [
            {
                required: true,
                errorMessage: '请输入驳回原因',
            },
        ],
    },
}


const open = (data) => {
    formData.value.order_id = data
    skyBasePopupRef.value.open()
}

// 订单驳回
const confirm = async () => {
    const res = await qly.api.order.order_refund.check(formData.value)
    if (res.code === 1) {
        emits('success')
        qly.dialog.toast({title: '驳回成功'})
        skyBasePopupRef.value.close()
    } else {
        qly.dialog.apiError(res).catch()
    }
}
defineExpose({
    open
})
</script>
<style scoped lang="scss">
.form-box{
    padding: 32rpx;
    box-sizing: border-box;
}
</style>
